package cn.com.miao.lynx.common.data.mybatis.config;

import cn.com.miao.lynx.common.data.core.CustomAuditorAware;
import cn.com.miao.lynx.common.data.mybatis.handler.EntityMetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import lombok.AllArgsConstructor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;

/**
 * MybatisPlusConfig
 *
 * @title: MybatisPlusConfig
 * @description:
 * @author: dengmiao
 * @create: 2019-12-26 15:28
 **/
@AllArgsConstructor
@Configuration
@MapperScan({"cn.com.miao.lynx.**.mapper"})
public class MybatisPlusAutoConfig {

    @Bean
    @ConditionalOnMissingBean
    public AuditorAware<String> auditorAware() {
        return new CustomAuditorAware();
    }

    /**
     * 分页插件bean
     * @return 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    /**
     * 新增，修改 公共字段填充
     * @param auditorAware spring data 用户审计
     * @return 元字段填充处理器
     */
    @Bean
    public EntityMetaObjectHandler entityMetaObjectHandler(AuditorAware<String> auditorAware) {
        return new EntityMetaObjectHandler(auditorAware);
    }
}
